public class MyCircularQueue {
    private int[] data;
    private int first;
    private int last;

    //构造器，设置队列长度为 k
    public MyCircularQueue(int k) {
        this.data = new int[k];
    }

    // 向循环队列插入一个元素。如果成功插入则返回真。
    public boolean enQueue(int value) {
        if (!isFull()) {
            this.data[this.last] = value;
            this.last = (this.last + 1) % this.data.length;
            return true;
        } else {
            return false;
        }
    }

    // 从循环队列中删除一个元素。如果成功删除则返回真
    public boolean deQueue() {
        if (!isEmpty()) {
            this.first = (this.first + 1) % this.data.length;
            return true;
        } else {
            return false;
        }
    }

    //从队首获取元素。如果队列为空，返回 -1
    public int Front() {
        if (!isEmpty()) {
            return this.data[this.first];
        } else {
            return -1;
        }
    }

    //获取队尾元素。如果队列为空，返回 -1
    public int Rear() {
        if (!isEmpty()) {
            return this.data[this.last];
        } else {
            return -1;
        }
    }

    //检查循环队列是否为空
    public boolean isEmpty() {
        return this.last == this.first;
    }

    //检查循环队列是否已满
    public boolean isFull() {
        return (this.last + 1) % this.data.length == this.first;
    }
}
